package logic

import (
	"context"
	"user_srv/userclient"

	"api/internal/svc"
	"api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type AddPositionLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewAddPositionLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddPositionLogic {
	return &AddPositionLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *AddPositionLogic) AddPosition(req *types.AddPositionrequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	add, err := l.svcCtx.UserSrv.AddPosition(l.ctx, &userclient.AddPositionRequest{
		PositionName:   req.PositionName,
		Category:       req.Category,
		Address:        req.Address,
		Salary:         float32(req.Salary),
		WorkExperience: req.WorkExperience,
		Graduate:       req.Graduate,
		Info:           req.Info,
		UserId:         req.UserId,
	})
	if err != nil {
		return &types.Response{
			Msg:  err.Error(),
			Code: 500,
			Data: nil,
		}, nil
	}
	return &types.Response{
		Msg:  "发布成功",
		Code: 200,
		Data: add,
	}, nil
}
